﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 编码自动生成类型
    /// </summary>
    public partial class CF_CodeType : BusEntity
    {
        /// <summary>
        /// 类型编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 类型名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 连接字符
        /// </summary>
        public string JoinChar { get; set; }
    }

    public partial class CF_CodeType : BusEntity
    {
        /// <summary>
        /// 编码规则
        /// </summary>
        public List<CF_CodeRule> CodeRules { get; set; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class CF_CodeTypeTypeConfig : BusEntityTypeConfig<CF_CodeType>, IEntityTypeConfiguration<CF_CodeType>
    {
        public override void Configure(EntityTypeBuilder<CF_CodeType> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();
            builder.Property(p => p.JoinChar).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired().HasDefaultValue("");
            #endregion

            #region 备注
            builder.HasComment("编码自动生成类型");
            builder.Property(p => p.Code).HasComment("类型编码");
            builder.Property(p => p.Name).HasComment("类型名称");
            builder.Property(p => p.JoinChar).HasComment("连接字符");
            #endregion

            #region 种子数据
            builder.HasData(new CF_CodeType() { Id = $"{EntityDefinition.DefSysCode}_CF_User_Code", Code = "CF_User_Code", Name = "用户编号", JoinChar = "", CreateUserId = "1", ModifyUserId = "1" });
            #endregion
        }
    }
}
